import type {WLBuildMsgRet, WLMsgHeader} from "@/proto/weilapb_wrapper_data";
import type {WL_IDbMsgData, WL_IDbUserInfo} from "@/proto/weilapb_external_data";

interface WL_PromiseCallback {
    resolve(data: any): any;
    reject(reason: any): any;
}

interface WL_ExtEvent {
    event: WL_ExtEventID;
    data: any
}

enum WL_NetworkState {
    NET_CONNECTING_STATE,
    NET_CONNECTED_STATE,
    NET_DISCONNECTING_STATE,
    NET_DISCONNECTED_STATE
}

enum WL_NetworkEventID {
    NET_EXCEPTION_IND_EVT,
    NET_CONNECT_EVT,
    NET_DISCONNECT_EVT,
    NET_SEND_DATA_EVT,
    NET_STATE_IND_EVT,
    NET_MSG_RECV_IND_EVT
}

interface WL_NetworkEvent {
    eventId: WL_NetworkEventID;
    eventData: any;
}

interface WL_PbMsgData {
    header: WLMsgHeader;
    pbMsgData: any;
}


/**
 *     WL_EXT_NET_EXCEPTION_IND,               // 网络出现异常的信息
 *     WL_EXT_NET_DISCONNECTED_IND,            // 网络出故障了
 *     WL_EXT_NET_LOGIN_FAILED_IND,            // 登录失效了
 *     WL_EXT_AUDIO_ITEM_PLAY_END_IND,         // 一条语音播放完毕
 *     WL_EXT_AUDIO_DATA_PLAY_PROGRESS_IND,    // 告知当前播放音频的进度  数据是消息和帧数 {msgData: WL_IDbMsgData, frameCount: number}
 *     WL_EXT_CURRENT_PLAY_AUDIO_IND,          // 告知当前播放的消息  当前播放的消息 msgData: WL_IDbMsgData
 *     WL_EXT_NEW_MSG_RECV_IND,                // 收到新的消息 收到的新消息 msgData: WL_IDbMsgData
 *     WL_EXT_NEW_SESSION_OPEN_IND,            // 新会话打开
 *     WL_EXT_MSG_SENDING_IND,                 // 消息发送中
 *     WL_EXT_MSG_SEND_IND,                    // 消息已发送
 *     WL_EXT_PTT_RECORD_IND,                 // 当前已发送的PTT部分提示  info: WL_PttRecordInd
 *     WL_EXT_ACCOUNT_WAS_KICKED_OUT,         // 账号被踢
 *
 *
 *     WL_EXT_COMMON_SESSION_CHANGE_IND,       // 服务会话状态变更
 *     WL_EXT_LOCATION_CTRL_IND,               // 会话成员位置变更提示
 */
enum WL_ExtEventID {
    WL_EXT_NET_EXCEPTION_IND,               // 网络出现异常的信息
    WL_EXT_NET_DISCONNECTED_IND,            // 网络出故障了
    WL_EXT_NET_LOGIN_FAILED_IND,            // 登录失效了
    WL_EXT_AUDIO_ITEM_PLAY_END_IND,         // 一条语音播放完毕
    WL_EXT_AUDIO_DATA_PLAY_PROGRESS_IND,    // 告知当前播放音频的进度
    WL_EXT_AUDIO_DATA_PLAY_END_IND,         // 告知当前播放的音频结束
    WL_EXT_CURRENT_PLAY_AUDIO_IND,          // 告知当前播放的消息
    WL_EXT_NEW_MSG_RECV_IND,                // 收到新的消息
    WL_EXT_NEW_SESSION_OPEN_IND,            // 新会话打开
    WL_EXT_MSG_SENDING_IND,                 // 消息发送中
    WL_EXT_MSG_SEND_IND,                    // 消息已发送
    WL_EXT_PTT_RECORD_IND,                 // 当前已发送的PTT部分提示
    WL_EXT_ACCOUNT_WAS_KICKED_OUT,         // 账号被踢


    WL_EXT_COMMON_SESSION_CHANGE_IND,       // 服务会话状态变更
    WL_EXT_LOCATION_CTRL_IND,               // 会话成员位置变更提示
}

interface WL_LoginParam {
    retryCount: number;
    account: string;
    password: string;
    countryCode: string;
    md5: boolean;
    callback: WL_PromiseCallback|undefined;
}

interface WL_PttPayload {
    frameCount: number;
    data: Uint8Array;
}

interface PttCoreListener {
    onRecordPttPacketInd(pttPacket: WL_PttPacket): void;
    onAudioItemPlayEnd(msgData: WL_IDbMsgData): void;
    onPlayAudioData(msgData: WL_IDbMsgData, frameCount: number): void;
    onCurrentPlayAudioMsg(msgData: WL_IDbMsgData): void;
    onRecorderErrorInd(error: string): void;
}

interface WL_PttAudioItem {
    id: string;
    msgData: WL_IDbMsgData;
    payloadList: WL_PttPayload[];
    priority: number;
    isCompleted: boolean;
    recvWaitTimerId: any;
    playIndex: number;
    playerType: number;
    shouldSave: boolean;
    playEnd: boolean;
}

enum WL_PttPackType {
    PTT_FIRST_PACK = 0x00,
    PTT_INTER_PACK = 0x01,
    PTT_END_PACK = 0x02,
    PTT_WHOLE_PACK = 0x03
}

enum WL_PttAudioPlayState {
    PTT_AUDIO_PLAYING_START,
    PTT_AUDIO_PLAYING,
    PTT_AUDIO_PLAYING_END
}

interface WL_PttPacket {
    seq: number;
    seqInPackage: number;
    sourceType: number;
    frameCount: number;
    mark: WL_PttPackType;
    data: Uint8Array;
}

enum WLPlayerType {
    STREAM_PLAYER,
    SINGLE_PLAYER
}

enum WL_PttRecordState {
    PTT_AUDIO_RECORDING_START,
    PTT_AUDIO_RECORDING,
    PTT_AUDIO_RECORDING_END
}

interface WL_PttRecordInd {
    msgData: WL_IDbMsgData;
    state: WL_PttRecordState;
}

interface WL_MsgDataInfo {
    senderInfo: WL_IDbUserInfo|undefined;
    msgData: WL_IDbMsgData;
}


interface WL_CoreInterface {
    sendExtEvent(event: WL_ExtEventID, data: any): void;
    sendPbMsg(buildPbMsg: WLBuildMsgRet, timeout?: number, isLoginMsg?: boolean): Promise<any>;
    rspPbMsg(seq: number, resultCode: number, data: any): void;
    registerPbMsgHandler(serviceId: number, handler: (data: any) => void): void;
    executeCoreFunc(funcName: string, ...argvs: any[]): Promise<any>;
}

interface WL_PbMsgHandler {
    (data:any): void;
}

interface WL_MsgDataErrorInfo {
    errCode: number;
    errMsg: string;
}

interface WL_LocationReportInfo {
    sessionId: string;
    sessionType: number;
    status: boolean;
    frequency: number;
    duration: number;
}

export {
    WL_NetworkState, WL_NetworkEventID, WL_PttPackType,
    WL_ExtEventID, WLPlayerType, WL_PttAudioPlayState,
    WL_PttRecordState
}

export type {
    WL_NetworkEvent, WL_PbMsgData, WL_CoreInterface, WL_LoginParam,
    WL_PttPayload, WL_PttAudioItem, WL_PttPacket, WL_PromiseCallback,
    PttCoreListener, WL_PttRecordInd, WL_PbMsgHandler, WL_ExtEvent, WL_MsgDataInfo, WL_MsgDataErrorInfo, WL_LocationReportInfo
}
